<template>
  <div class="container">
    <template v-if="'Add' in auth">
      <xy-table
        :addFormDTO="addForm"
        :api="api"
        :columns="columns"
      >
        <!-- <template #header=""><span></span></template> -->

        <!-- <template #check> <span></span></template> -->
        <el-table-column :label="$language.local('role_type')">
          <template slot-scope="scope">{{ roleType[scope.row.role_type] }}</template>
        </el-table-column>
      </xy-table>
    </template>
    <div
      class="pb-2"
      v-else
    >
      <el-collapse
        align="center"
        bgcolor="#cd8846"
        class
        v-model="activeNames"
      >
        <el-collapse-item name="1">
          <div
            class="title"
            slot="title"
          >
            <h1>{{ $language.local("UserInfo") }}</h1>
          </div>
          <display-table :model="user"></display-table>
        </el-collapse-item>
        <!-- <el-collapse-item name="2">
          <div
            class="title"
            slot="title"
          >
            <h1>{{ $language.local("RoleInfo") }}</h1>
          </div>
          <display-table :model="user.roleRight"></display-table>
        </el-collapse-item>-->
        <el-collapse-item name="3">
          <div
            class="title"
            slot="title"
          >
            <h1>{{ $language.local("MerchantInfo") }}</h1>
          </div>
          <display-table :model="merchantInfo"></display-table>
        </el-collapse-item>
        <el-collapse-item name="4">
          <div
            class="title"
            slot="title"
          >
            <h1>{{ $language.local("bankcard") }}</h1>
          </div>
          <template v-for="(card, index) in merchantInfo.backcard">
            <display-table
              :key="index"
              :model="card"
            ></display-table>
          </template>
        </el-collapse-item>
      </el-collapse>
    </div>
  </div>
</template>

<script>
import API from "../../plugins/api";
export default {
  data() {
    return {
      activeNames: ["1"],
      user: this.$store.getters.user,
      auth: "",
      merchantInfo: "",
      api: new API("/api/manager/GetList"),
      columns: {
        user_name: "登录用户名",
        real_name: "姓名",
        BranchName: "归属企业",
        // role_type: 0,

        telephone: "电话",
        add_time: "添加时间",
        is_lock: 0,
      },
      addForm: {
        role_id: "",
        // user_name: "string",
        BranchName: "",
        user_name: "",

        // busnieseNum: "",
        // type: 0,

        password: "",
        // salt: "",
        real_name: "",
        telephone: "",
        email: "",
        is_lock: 0,
        ParentId: 0,
        // TID: 0,
        // MID: 0,
        // SID: 0,
        // AID: 0,
        // PID: 0,
        // add_time: "2021-06-10T06:51:41.756Z",
      },
      roleType: {
        2: "服务商用户",
        3: "企业用户",
        4: "税务监管",
        5: "代理商负责人",
        6: "平台财务",
        7: "平台运营主管",
        51: "代理商商务经理",
        71: "平台运营岗",
        99: "平台管理",
      },
    };
  },
  created() {
    const menuName = this.$route.matched[1].path.slice(1);
    this.auth = this.$store.getters.rights[menuName];

    if (!this.auth && this.api) {
      this.auth = this.$store.getters.rights[this.api.entity];
    }
    console.log("权限:", this.auth);
  },
  mounted() {
    this.getMerchantInfo();
  },
  methods: {
    async getMerchantInfo() {
      const response = await this.$http.get(
        `/api/Merchant/GetModel/${this.user.branchid}`
      );
      this.merchantInfo = response.data.Data;
      console.log(this.merchantInfo);
    },
  },
};
</script>

<style lang="less" scoped></style>
